﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
  <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <c:set var="ctx" value="${pageContext.request.contextPath}" />
    <html>

    <head>
      <link rel="stylesheet" href="${ctx}/common/common.css" />
      <title>Title</title>
      <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/layui/css/layui.css" media="all" />
      <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/style/admin.css" media="all" />
      <script src="${ctx}/common/plugins/layuiadmin/layui/layui.js"></script>
    </head>

    <body>
      <!--主体内容层-->
      <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
          <div class="layui-col-md12 layui-col-space15">
            <form>
              <!--输入框内容盒子-->
              <div class="layui-col-md12">
                <!--输入框-->
                <div class="layui-col-md4">
                  <label class="layui-form-label">产品名称</label>
                  <div class="layui-input-block">
                    <input type="text" name="name" id="name" lay-verify="required" placeholder="请输入产品名称"
                      autocomplete="off" class="layui-input" />
                  </div>
                </div>
              </div>
              <div style="width: 100%; text-align: right" class="layui-btn-group paramBtn">
                <button data-type="reloadProcess" type="button" class="layui-btn layui-btn-sm layui-btn-danger">
                  查询
                </button>
                <button data-type="resetProcess" type="reset" class="layui-btn layui-btn-sm layui-btn-danger">
                  重置
                </button>
              </div>
            </form>
            <!--通用table表格-->

            <table class="layui-table" id="processReload"
              lay-data="{ url:'${ctx }/productProcess/queryProductProcessList', page:true,groups:5}" lay-filter="demo">
              <thead>
                <tr>
                  <th lay-data="{field:'standard_num'}">产品编码</th>
                  <th lay-data="{field:'name'}">产品名称</th>
                  <th lay-data="{field:'specifications'}">规格</th>
                  <th lay-data="{field:'unit'}">单位</th>
                  <th lay-data="{field:'right',toolbar:'#barDemo'}">操作</th>
                </tr>
              </thead>
            </table>
          </div>
        </div>
      </div>
      <script type="text/html" id="barDemo">
      <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="check">详细</a>
      <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">配置工艺</a>
    </script>
    </body>
    <script>
      layui.use("table", function () {
        var loading = layer.msg("数据加载中...");
        var table = layui.table;
        table.render({
          done: function () {
            layer.close(loading);
          },
        });
        //监听filter为demo的table中的工具条
        table.on("tool(demo)", function (obj) {
          var data = obj.data;
          if (obj.event === "detail") {
            //配置工艺
            window.location.href = "${ctx}/productProcess/toProcess?id=" + obj.data.id;
            } else if (obj.event === "check" && obj.data.workId != undefined ) {
            //跳转详细页
                window.location.href = "${ctx}/productProcess/productProcessView?id=" + obj.data.id + "&wordId=" + obj.data.workId;
            }else if (obj.event === "check" && obj.data.workId == undefined ){
                //跳转详细页
                window.location.href = "${ctx}/productProcess/productProcessView?id=" + obj.data.id ;
          }
        });

        var $ = layui.$,
          active = {
            reloadProcess: function () {
              //条件查询
              var name = document.getElementById("name").value;
              table.reload("processReload", {
                where: {
                  name: name,
                },
              });
            },
            resetProcess: function () {
              table.reload("processReload", {
                where: {
                  name: "",
                },
              });
            },
          };

        $(".demoTable .layui-btn").on("click", function () {
          var type = $(this).data("type");
          active[type] ? active[type].call(this) : "";
        });
        //给按钮绑定active中的方法
        $(".paramBtn .layui-btn").on("click", function () {
          var type = $(this).data("type");
          //查看是active这个json中是否有type这个方法，如果有调用，如果没有不知心；
          active[type] ? active[type].call() : "";
        });
      });
    </script>

    </html>